import JsonP from 'jsonp';
import axios from 'axios';


const baseApi = 'https://www.easy-mock.com/mock/5c49ecd86be884188ec7be52/storage-manager/api';

export default class Axios {
    static jsonp(options) {
        return new Promise((resolve, reject) => {
            JsonP(options.url, {
                param: 'callback'
            }, function (err, response) {
                if (response.status === 'success') {
                    resolve(response);
                } else {
                    reject(response.message);
                }
            })
        });
    }

    static ajax(options) {
        return new Promise((resolve, reject) => {
            axios({
                url: options.url,
                method: options.method || 'get',
                baseURL: options.baseURL || baseApi,
                timeout: 5000,
                params: options.data || ''
            }).then(res => {
                if (res.status === 200) {
                    resolve(res)
                } else {
                    reject(res);
                }
            });
        });
    }
}